
<body>

    <div class="warp">
        <!--header-->
        <header class="hd">
            <a href="javascript:history.go(-1)" class="l-icon only-icon">
                <i class="iconfont icon-left1"></i>    
            </a>

            <p class="tit2">
                忘记密码
            </p>
        </header>

        <div class="back-pwd-form">
            <div class="input-bar">
                <span>
                    <i class="iconfont icon-shouji"></i>
                </span>
                <input type="text" placeholder="请输入手机号码" id="mobile">
            </div>
            <div class="verifica-bar">
                <span>
                    <i class="iconfont icon-anquan"></i>
                </span>
                 <input type="text" placeholder="请输入验证码" id="captcha">

                 <a href="javascript:0;" class="sendmsg send-standby" id="send-captcha">
                     发送验证码
                 </a>
            </div>
             <div class="input-bar">
                <span>
                    <i class="iconfont icon-suo"></i>
                </span>
                <input type="password" placeholder="请输入6-12位新密码" id="password">
                
            </div>
            <a class="login-btn" id="submit">
                修改并登陆
            </a>          
        </div>



    </div>

    <script src="<?php echo $base_url;?>static/dist/js/base.js"></script>

    <script>
        //验证码倒计时
        var iTimer = 0;
        // 矫正rem
        function correctrem() {
            var rem_full_width = $("<div id='rem-test' style='width:7.5rem'></div>").appendTo($('body')).width();
            var device_width = Math.min(document.documentElement.clientWidth, 640);
            if (rem_full_width !== device_width) {
                document.documentElement.style.fontSize = (device_width / 7.5) * (device_width / rem_full_width) + 'px';
            }
            $('#rem-test').remove();
        }
        correctrem();
        $(function () {

        })

        //发送验证码
        $('#send-captcha').on("click",function() {
            var mobile = $('#mobile').val();
            var pattern = /^1[34578]\d{9}$/;
            console.log($(this).hasClass("send-standby"))
            if (!pattern.test(mobile)) {
                alert("请填写11位数字的正确号码");
                return;
            }
            if (!navigator.onLine) {
                alert("网络连接异常，请检查网络");
                return;
            }
            var self = this;
            if ($(this).hasClass("send-standby")) {
                // console.log('cc');
                $.getJSON("/home/account/sms_port?phone=" + mobile + "&type=1", function(data) {
                    if(data.errcode != 0)
                    {
                        alert(data.errmsg);
                        resetCaptchaBtn();
                    } else { //  发送成功

                        timeCount();
                    }
                });
                $(self).removeClass("send-standby");
            }

        });

        function resetCaptchaBtn() {
            clearInterval(iTimer);
            $('#send-captcha').text('发送验证码');
            $('#send-captcha').addClass("send-standby");
        }

        //定时器
        function timeCount() {
            var i = 60;
            iTimer = setInterval(function() {
                i <= 0 ? clearInterval(iTimer) : i--;
                $('#send-captcha').text(i + '秒');
                if (i == 0) {
                    resetCaptchaBtn();
                }
            }, 1000);
        }

        //登录
        $('#submit').on("click",function() {
            var mobile = $('#mobile').val();
            var password = $('#password').val();
            var captcha = $('#captcha').val();
            var pattern = /^1[34578]\d{9}$/;

            if (!pattern.test(mobile)) {
                alert("请填写11位数字的正确号码");
                return;
            }
            if (password == "") {
                alert("请填写密码");
                return;
            }

            if(password.length<6 || password.length>12){
                alert("请输入6-12位密码");
                return;
            }

            //帮助登录
            $.post("<?php echo $base_url; ?>/home/account/updatePassword", {
                'mobile': mobile,
                'password': password,
                'captcha' : captcha
            }, function(json) {
                if (json.result == 0) {
                    <?php if(empty($back_url)): ?>
                    window.location.href = "<?php echo $base_url; ?>home";
                    <?php else: //跳转到上一个页面?>
                    window.location.href = decodeURIComponent("<?php echo urlencode($back_url); ?>");
                    <?php endif; ?>
                    return;
                }
                else
                {
                    alert(json.message);
                }
            }, 'json');
        });

    </script>

</body>

</html>